﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using NUnit.Framework;
using Chbl.Scheduling;

namespace Chbl.Test
{
    [TestFixture]
    public class SchedulerTests
    {
        [Test]
        public void CreateSchedule()
        {
            var scheduler = new Scheduler
                                {
                                    Teams = new List<ITeam>
                                                {
                                                    new TestTeam {Id = 1, Name = "Team1"},
                                                    new TestTeam {Id = 2, Name = "Team2"}
                                                },
                                    StartDate = new DateTime(2011, 11, 11),
                                    TourIntervalInDays = 7
                                };
            var schedule = scheduler.Generate();
            Assert.AreEqual(1, schedule.GamesDaysList.Count);
            Assert.AreEqual(1, schedule.GamesList.Count);
            TestCreateGame(scheduler, schedule);
        }

        private void TestCreateGame(Scheduler scheduler, Schedule schedule)
        {
            IGame game = schedule.GamesList[0];
            Assert.AreEqual(scheduler.StartDate, game.Date);
            Assert.AreEqual(1, game.GameOrder);
            Assert.AreEqual(scheduler.Teams[0], game.RoadTeam);
            Assert.AreEqual(scheduler.Teams[1], game.HomeTeam);
            Assert.AreEqual(1, game.TourNumber);
        }

        [Test, ExpectedException(typeof(InvalidOperationException))]
        public void IsValidDataReturnsFalse()
        {
            var scheduler = new Scheduler
            {
                Teams = new List<ITeam>
                                                {
                                                    new TestTeam {Id = 1, Name = "Team1"},
                                                },
                StartDate = new DateTime(2011, 11, 11),
                TourIntervalInDays = 7
            };
            scheduler.Generate();
        }
    }
}
